<template>
	<view>
		<view class="bg-white">
			<u-tabs @click="clickTab" :scrollable="false" :list="list1" lineWidth="30" lineColor="#3389FF" :activeStyle="{
			            color: '#3389FF',
			            fontWeight: 'bold',
			            transform: 'scale(1.05)'
			        }" :inactiveStyle="{
			            color: '#606266',
			            transform: 'scale(1)'
			        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;">
			</u-tabs>
		</view>
		<view class="padding">
			<view class="end_layout">
				<view style="margin-bottom: 30rpx;">
					<u-button @click="toAdd('','新增项目进度')" type="primary" icon="plus" text="新增" size="small"></u-button>
				</view>
			</view>
			<u-empty v-if="dataList.length==0" marginTop='100' mode="data"
				:icon="require('@/static/mine/empty.png')"></u-empty>
			<view @click="toAdd(item.baseId,'项目进度详情')" v-for="(item,index) in dataList" :key="index" class="p-area">
				<view class="between_layout">
					<view class="p-name">{{item.progressReportDate}}</view>
					<u-tag plain size="mini" v-if="item.state==2" text="审核退回" type="error"></u-tag>
					<u-tag plain size="mini" v-if="item.state==1" text="待审核" type="warning"></u-tag>
					<u-tag plain size="mini" v-if="item.state==0" text="审核通过" type="success"></u-tag>
				</view>
				<view v-if="item.state==2" style="padding: 10rpx 16rpx;margin-top: 20rpx;font-size: 20rpx;"
					class="bg-red light">
					<view class="sub-state text-red">
						退回原因：{{item.auditOpinion}}</view>
				</view>
				<view style="flex-wrap: wrap;" class="start_layout padding-tb-sm">
					<view class="item-tag">当月到位资金：{{item.currentMonthFunds ? item.currentMonthFunds + '万元' : "-"}}
					</view>
				</view>
				<view class="between_layout end-time solid-top padding-top-sm">
					<view class="start_layout">
						建设进度：
						<view style="width: 150rpx;">
							<u-line-progress height="10" :percentage="item.constructionProgress"
								activeColor="#ff0000"></u-line-progress>
						</view>
					</view>
					<view class="end_layout">
						<u-button v-if="item.state==1&&roles.indexOf('company')==-1"
							:customStyle="{height: '50rpx',borderRadius: '10rpx',marginLeft:'10rpx'}"
							@click.native.stop="toAudit(item.baseId)" text="审核" type="success" size="small"></u-button>
						<u-button v-if="item.state!=1"
							:customStyle="{height: '50rpx',borderRadius: '10rpx',marginLeft:'10rpx'}"
							@click.native.stop="toAdd(item.baseId,'修改项目进度')" text="修改" type="primary"
							size="small"></u-button>
						<u-button v-if="item.state==0&&roles.indexOf('company')==-1"
							:customStyle="{height: '50rpx',borderRadius: '10rpx',marginLeft:'10rpx'}"
							@click.native.stop="toDelete(item.baseId)" text="删除" type="error" size="small"></u-button>
					</view>
				</view>
			</view>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
		<u-loadmore v-show="dataList.length>0" :status="status" />
		<auditPop ref="auditPopRef" @popSuccess="search" :type='4'></auditPop>
	</view>
</template>

<script>
	import {
		getProgressList,
		delProjectProgress
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				policyForm: {
					pageNum: 1,
					pageSize: 10,
					state: null,
					projectId: null
				},
				list1: [{
					name: '全部',
					state: null
				}, {
					name: '待审核',
					state: 1
				}, {
					name: '审核通过',
					state: 0
				}, {
					name: '审核退回',
					state: 2
				}],
				status: 'nomore',
				total: 0,
				dataList: [],
				scrollTop: 0,
				roles: [],
			}
		},
		onLoad(option) {
			this.roles = uni.getStorageSync("roleinfo")
			this.policyForm.projectId = option.id
		},
		onShow() {
			this.search()
		},
		onReachBottom() {
			if (this.policyForm.pageNum >= this.total / 10) {
				this.status = 'nomore'
				return
			} else {
				this.status = 'loading'
				this.policyForm.pageNum++
				this.init()
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			init() {
				uni.showLoading({
					title: '加载中'
				});
				getProgressList(this.policyForm).then(response => {
					if (response.code == 200) {
						uni.hideLoading();
						this.dataList = [...this.dataList, ...response.rows]
						this.total = response.total
					} else {
						uni.hideLoading();
						uni.showToast({
							title: response.msg,
							icon: 'none',
							duration: 3000
						})
					}
					this.status = 'nomore'
				});
			},
			clickTab(item) {
				this.policyForm.state = item.state
				this.policyForm.pageNum = 1
				this.dataList = []
				this.init()
			},
			search() {
				this.policyForm.state = null
				this.policyForm.pageNum = 1
				this.dataList = []
				this.init()
			},
			toAdd(id, name) {
				uni.navigateTo({
					url: '/pages_two/progress/add?id=' + this.policyForm.projectId + '&subId=' + id + '&name=' +
						name
				})
			},
			toAudit(item) {
				this.$refs.auditPopRef.openPop(item)
			},
			toDelete(id) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认删除数据吗?',
					confirmText: '删除',
					success(res) {
						if (res.confirm) {
							delProjectProgress(id).then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '操作成功！',
										icon: 'none',
										duration: 3000
									})
									that.search()
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 3000
									})
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.p-area {
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 30rpx;
		margin-bottom: 30rpx;

		.p-name {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
		}

		.item-tag {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #3389FF;
			padding: 8rpx 12rpx;
			background: rgba(51, 137, 255, 0.1);
			border-radius: 6rpx;
		}

		.end-time {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #999999;
		}
	}
</style>